package com.shuyuntu.proposal.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;

import javax.persistence.*;
import java.util.HashSet;
import java.util.Set;

/**
 * Created by limeng on 16/5/16.
 */
@Entity
@Table(name = "permission")
public class Permission {
    /**
     * 权限id
     */
    private Integer id;

    /**
     * 目录的位置(层级结构)
     */
    private String category;

    /**
     * 权限的简介
     */
    private String description;

    /**
     * 图标
     */
    private String icon;

    /**
     * 路径
     */
    private String href;

    /**
     * 拥有该权限的角色列表
     */
    @JsonIgnore
    private Set<Role> roles = new HashSet<>();

    /**************getters && setters***************/
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    @Column(length = 10, nullable = true, unique = true)
    public String getCategory() {
        return category;
    }

    public void setCategory(String category) {
        this.category = category;
    }

    @Column(length = 20, nullable = false)
    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    @ManyToMany(mappedBy = "permissions")
    public Set<Role> getRoles() {
        return roles;
    }

    public void setRoles(Set<Role> roles) {
        this.roles = roles;
    }

    @Column(length = 20)
    public String getIcon() {
        return icon;
    }

    public void setIcon(String icon) {
        this.icon = icon;
    }

    @Column(length = 50)
    public String getHref() {
        return href;
    }

    public void setHref(String href) {
        this.href = href;
    }

    /**
     * 无参构造
     */
    public Permission() {
    }
}
